function GetQueryString(key) {
	// key为url变量名称
	var urlGets = location.search.substr(1);
	if(urlGets.length > 0) {
		start = urlGets.indexOf(key + '=');
		if(start != -1) {
			start = start + key.length + 1;
			end = urlGets.indexOf('&', start)
			if(end == -1) {
				end = urlGets.length
			}
			return decodeURIComponent(urlGets.substring(start, end))
		}
	}
	return '';
}
var murl;
var bordimg = document.getElementById('bordimg');
var bordname = document.getElementById('bordname');
var bordsize = document.getElementById('bordsize');
var bordsizenum = document.getElementById('bordsizenum');
var bordprice = document.getElementById('bordprice');
var bordprice_detail = document.getElementById('bordprice_detail');
var bordtime = document.getElementById('bordtime');
/*var bordtime_detail = document.getElementById('bordtime_detail');*/
var least = document.getElementById('least');
var xfway = document.getElementById('xfway');0
/*var today = document.getElementById('today');*/
var realname = document.getElementById('realname');
var realnum = document.getElementById('realnum');
var details_detail = document.getElementById('details_detail');
var material = document.getElementById('material');
var bord_btn = document.getElementById('bord_btn');
var certification_detail = document.getElementById('certification_detail');

refresh.addEventListener('touchstart', function() {
	refresh.style.background = '#D8D8D8'
});
refresh.addEventListener('touchend', function() {
	refresh.style.background = 'white';
	setTimeout(function() {
		refresh.style.display = 'none';
		get();
	}, 500)
});
function get() {

	$.ajax({
		type: 'get',
		url: httpAdress + '/api/borrow/product/selectbyid',
		contentType: "application/json; charset=utf-8",

		data: {
			'id': GetQueryString('mproid')
          /*  'id': 11*/
		},
		dataType: 'jsonp',
		jsonp: "callback",
		jsonpCallback: "successCallback",
		success: function(data) {
			console.log(data);
			var mydata = data.data;
			murl = mydata.murl;
           console.log(JSON.stringify(data));
			bordimg.src = httpAdress + mydata.logo;
			xfway.innerHTML = mydata.applicant;
			bordname.innerHTML = mydata.name;
			bordsizenum.innerHTML = mydata.loans_scope;
			/*bordtime_detail.innerHTML = mydata.term_range;*/
			bordprice_detail.innerHTML = mydata.rate;
			var str = '<span class="need" id="need">所需材料:</span><br />';
			for(var i = 0; i < mydata.mi.length; i++) {
				str += '<span id="need_detail" class="gray item-fonts">' +
					mydata.mi[i] +
					'</span><br />';
			}
            var htmls='';
            console.log(mydata.process);
			for(var i in mydata.process){
				var item=mydata.process[i];

                if(i==0){
                    htmls+='<div class="text-center"><img src="'+item.imgs+'" class="process-item-img">' +
                        '<div class="process-item-title">'+item.title+'</div>' +
                        '</div>'
                }else{
                    htmls+='<img src="../../img/right-icon.png" class="process-item-img-right">'+
                        '<div class="text-center"><img src="'+item.imgs+'" class="process-item-img">' +
                        '<div class="process-item-title">'+item.title+'</div>' +
                        '</div>'
                }

			}
        $('#xfflow').html( htmls);
			var str1 = "";
			for(var i = 0; i < mydata.ac.length; i++) {
				str1 += '<span  class="gray item-fonts">' +
					mydata.ac[i] +
					'</span><br />';
			}
			for(var i = 0; i < mydata.process.length; i++) {
				$('<span  class="gray item-fonts">' +
					mydata.process[i] +
					'</span><br />').appendTo("#xfxfflow");
			}
			material.innerHTML = str;
			realname.innerHTML = str1;
			certification_detail.innerHTML = mydata.repay_method;
			details_detail.innerHTML = mydata.detailed;
		},
		error: function() {
			mui.toast('加载失败，刷新一下');
			refresh.style.display = 'block';
		}
	});

	var pp = '';
	var mt = '';
	if(GetQueryString('pp') == '') {
		pp = 5000;
	} else {
		pp = GetQueryString('pp');
	}
	if(GetQueryString('mt') == '') {
		mt = 12;
	} else {
		mt = GetQueryString('mt');
	}
	bord_btn.addEventListener('tap', function(event) {
		var userid = localStorage.getItem("userid");
        //var userid="15123993171";
		if(userid == null || userid == "") {
			window.location.href = "../login/login.html?islogin";
		} else {
			$.ajax({
				type: 'get',
				url: httpAdress + '/api/borrow/record/addrecord',
				contentType: "application/json; charset=utf-8",
				data: {
					pid: GetQueryString('mproid'),
					money: pp,
					term: mt,
					channel: 3,
					name: GetQueryString('mdname'),
					type: 0,
					userid: localStorage.getItem("userid")
				},
				dataType: 'jsonp',
				jsonp: "callback",
				jsonpCallback: "successCallback",
				success: function(data) {
					document.location.href = murl;
				},
				error: function() {
					mui.toast('加载失败，刷新一下');
				}
			});
		}

	});
}
get();

var userup = localStorage.getItem('userid');
var arrqq = ['home.html', '../daikuan/daikuan.html', '../bank/credit_card.html', '../login/login.html'];
var muitabitem = document.getElementsByClassName('mui-tab-item');

